package com.gok.seasonmovie.util;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class CryptoUtil {
    private static final String ALGORITHM = "AES";
    private static final String TRANSFORMATION = "AES/ECB/PKCS5Padding";//加密模式、填充方式
    private static final byte[] KEY = "1234567890123456".getBytes(); //16字节密钥

    public static String encrypt(String input) throws Exception {
        SecretKey secretKey = new SecretKeySpec(KEY, ALGORITHM);
        Cipher cipher = Cipher.getInstance(TRANSFORMATION);
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);//初始化Cipher实例为加密模式，并传入密钥
        byte[] encryptedBytes = cipher.doFinal(input.getBytes());//加密
        return Base64.getEncoder().encodeToString(encryptedBytes);
    }

//    public static String decrypt(String input) throws Exception {
//        SecretKey secretKey = new SecretKeySpec(KEY, ALGORITHM);
//        Cipher cipher = Cipher.getInstance(TRANSFORMATION);
//        cipher.init(Cipher.DECRYPT_MODE, secretKey);
//        byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(input));
//        return new String(decryptedBytes);
//    }
}
